package com.zhaoxi.project.wms.service;

import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.project.wms.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 物品Service业务层处理
 *
 * @author zhaoxi
 * @date 2023-07-22
 */
@Service
public class ProductService extends BaseService {
  @Autowired
  private ProductMapper productMapper;

  //查询数据集合
  public List<PageData> getList(PageData pd) {
    return productMapper.getList(pd);
  }


  //新增
  public PageData add(PageData pd) {
    productMapper.add(pd);
    pd.put("createBy", this.getUsername());
    if (pd.getLong("id") != null) {
      List<PageData> list = pd.getListPd("picturePd");
      for (PageData pageData : list) {
        pageData.put("productId", pd.getLong("id"));
      }
      productMapper.addPictureBatch(list);
    }
    return this.success();
  }

  //更新
  public PageData edit(PageData pd) {
    productMapper.delPicture(pd.getLong("id"));
    productMapper.addPictureBatch(pd.getListPd("picturePd"));
    pd.put("updateBy", this.getUsername());
    return this.success(productMapper.edit(pd));
  }

  //删除
  public PageData del(Long id) {
    productMapper.del(id);
    return this.success(productMapper.del(id));
  }


  //产品图片列表
  public List<Long> getPictureList(PageData pd) {
    return productMapper.getPictureList(pd);
  }
}
